<template>
  <div>
    <div class="gva-form-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :rules="rule" label-width="80px">
        <el-form-item label="用户主键:" prop="FUserId">
          <el-input v-model="formData.FUserId" :clearable="true"  placeholder="请输入用户主键" />
       </el-form-item>
        <el-form-item label="工号:" prop="FEnCode">
          <el-input v-model="formData.FEnCode" :clearable="true"  placeholder="请输入工号" />
       </el-form-item>
        <el-form-item label="登录账户:" prop="FAccount">
          <el-input v-model="formData.FAccount" :clearable="true"  placeholder="请输入登录账户" />
       </el-form-item>
        <el-form-item label="登录密码:" prop="FPassword">
          <el-input v-model="formData.FPassword" :clearable="true"  placeholder="请输入登录密码" />
       </el-form-item>
        <el-form-item label="密码秘钥:" prop="FSecretkey">
          <el-input v-model="formData.FSecretkey" :clearable="true"  placeholder="请输入密码秘钥" />
       </el-form-item>
        <el-form-item label="真实姓名:" prop="FRealName">
          <el-input v-model="formData.FRealName" :clearable="true"  placeholder="请输入真实姓名" />
       </el-form-item>
        <el-form-item label="呢称:" prop="FNickName">
          <el-input v-model="formData.FNickName" :clearable="true"  placeholder="请输入呢称" />
       </el-form-item>
        <el-form-item label="头像:" prop="FHeadIcon">
          <el-input v-model="formData.FHeadIcon" :clearable="true"  placeholder="请输入头像" />
       </el-form-item>
        <el-form-item label="快速查询:" prop="FQuickQuery">
          <el-input v-model="formData.FQuickQuery" :clearable="true"  placeholder="请输入快速查询" />
       </el-form-item>
        <el-form-item label="简拼:" prop="FSimpleSpelling">
          <el-input v-model="formData.FSimpleSpelling" :clearable="true"  placeholder="请输入简拼" />
       </el-form-item>
        <el-form-item label="性别:" prop="FGender">
          <el-input v-model.number="formData.FGender" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="生日:" prop="FBirthday">
          <el-date-picker v-model="formData.FBirthday" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="手机:" prop="FMobile">
          <el-input v-model="formData.FMobile" :clearable="true"  placeholder="请输入手机" />
       </el-form-item>
        <el-form-item label="电话:" prop="FTelephone">
          <el-input v-model="formData.FTelephone" :clearable="true"  placeholder="请输入电话" />
       </el-form-item>
        <el-form-item label="电子邮件:" prop="FEmail">
          <el-input v-model="formData.FEmail" :clearable="true"  placeholder="请输入电子邮件" />
       </el-form-item>
        <el-form-item label="QQ号:" prop="FOICQ">
          <el-input v-model="formData.FOICQ" :clearable="true"  placeholder="请输入QQ号" />
       </el-form-item>
        <el-form-item label="微信号:" prop="FWeChat">
          <el-input v-model="formData.FWeChat" :clearable="true"  placeholder="请输入微信号" />
       </el-form-item>
        <el-form-item label="MSN:" prop="FMSN">
          <el-input v-model="formData.FMSN" :clearable="true"  placeholder="请输入MSN" />
       </el-form-item>
        <el-form-item label="机构主键:" prop="FCompanyId">
          <el-input v-model="formData.FCompanyId" :clearable="true"  placeholder="请输入机构主键" />
       </el-form-item>
        <el-form-item label="部门主键:" prop="FDepartmentId">
          <el-input v-model="formData.FDepartmentId" :clearable="true"  placeholder="请输入部门主键" />
       </el-form-item>
        <el-form-item label="安全级别:" prop="FSecurityLevel">
          <el-input v-model.number="formData.FSecurityLevel" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="单点登录标识:" prop="FOpenId">
          <el-input v-model.number="formData.FOpenId" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="微信OpenId:" prop="FWeChatOpenId">
          <el-input v-model="formData.FWeChatOpenId" :clearable="true"  placeholder="请输入微信OpenId" />
       </el-form-item>
        <el-form-item label="密码提示问题:" prop="FQuestion">
          <el-input v-model="formData.FQuestion" :clearable="true"  placeholder="请输入密码提示问题" />
       </el-form-item>
        <el-form-item label="密码提示答案:" prop="FAnswerQuestion">
          <el-input v-model="formData.FAnswerQuestion" :clearable="true"  placeholder="请输入密码提示答案" />
       </el-form-item>
        <el-form-item label="允许多用户同时登录:" prop="FCheckOnLine">
          <el-input v-model.number="formData.FCheckOnLine" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="允许登录时间开始:" prop="FAllowStartTime">
          <el-date-picker v-model="formData.FAllowStartTime" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="允许登录时间结束:" prop="FAllowEndTime">
          <el-date-picker v-model="formData.FAllowEndTime" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="暂停用户开始日期:" prop="FLockStartDate">
          <el-date-picker v-model="formData.FLockStartDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="暂停用户结束日期:" prop="FLockEndDate">
          <el-date-picker v-model="formData.FLockEndDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="排序码:" prop="FSortCode">
          <el-input v-model.number="formData.FSortCode" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="删除标记:" prop="FDeleteMark">
          <el-input v-model.number="formData.FDeleteMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="有效标志:" prop="FEnabledMark">
          <el-input v-model.number="formData.FEnabledMark" :clearable="true" placeholder="请输入" />
       </el-form-item>
        <el-form-item label="备注:" prop="FDescription">
          <el-input v-model="formData.FDescription" :clearable="true"  placeholder="请输入备注" />
       </el-form-item>
        <el-form-item label="创建日期:" prop="FCreateDate">
          <el-date-picker v-model="formData.FCreateDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="创建用户主键:" prop="FCreateUserId">
          <el-input v-model="formData.FCreateUserId" :clearable="true"  placeholder="请输入创建用户主键" />
       </el-form-item>
        <el-form-item label="创建用户:" prop="FCreateUserName">
          <el-input v-model="formData.FCreateUserName" :clearable="true"  placeholder="请输入创建用户" />
       </el-form-item>
        <el-form-item label="修改日期:" prop="FModifyDate">
          <el-date-picker v-model="formData.FModifyDate" type="date" placeholder="选择日期" :clearable="true"></el-date-picker>
       </el-form-item>
        <el-form-item label="修改用户主键:" prop="FModifyUserId">
          <el-input v-model="formData.FModifyUserId" :clearable="true"  placeholder="请输入修改用户主键" />
       </el-form-item>
        <el-form-item label="修改用户:" prop="FModifyUserName">
          <el-input v-model="formData.FModifyUserName" :clearable="true"  placeholder="请输入修改用户" />
       </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="back">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import {
  createXyoaUser,
  updateXyoaUser,
  findXyoaUser
} from '@/api/xyoaUser'

defineOptions({
    name: 'XyoaUserForm'
})

// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref, reactive } from 'vue'

const route = useRoute()
const router = useRouter()

const type = ref('')
const formData = ref({
            FUserId: '',
            FEnCode: '',
            FAccount: '',
            FPassword: '',
            FSecretkey: '',
            FRealName: '',
            FNickName: '',
            FHeadIcon: '',
            FQuickQuery: '',
            FSimpleSpelling: '',
            FGender: 0,
            FBirthday: new Date(),
            FMobile: '',
            FTelephone: '',
            FEmail: '',
            FOICQ: '',
            FWeChat: '',
            FMSN: '',
            FCompanyId: '',
            FDepartmentId: '',
            FSecurityLevel: 0,
            FOpenId: 0,
            FWeChatOpenId: '',
            FQuestion: '',
            FAnswerQuestion: '',
            FCheckOnLine: 0,
            FAllowStartTime: new Date(),
            FAllowEndTime: new Date(),
            FLockStartDate: new Date(),
            FLockEndDate: new Date(),
            FSortCode: 0,
            FDeleteMark: 0,
            FEnabledMark: 0,
            FDescription: '',
            FCreateDate: new Date(),
            FCreateUserId: '',
            FCreateUserName: '',
            FModifyDate: new Date(),
            FModifyUserId: '',
            FModifyUserName: '',
        })
// 验证规则
const rule = reactive({
})

const elFormRef = ref()

// 初始化方法
const init = async () => {
 // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (route.query.id) {
      const res = await findXyoaUser({ ID: route.query.id })
      if (res.code === 0) {
        formData.value = res.data.rexyoaUser
        type.value = 'update'
      }
    } else {
      type.value = 'create'
    }
}

init()
// 保存按钮
const save = async() => {
      elFormRef.value?.validate( async (valid) => {
         if (!valid) return
            let res
           switch (type.value) {
             case 'create':
               res = await createXyoaUser(formData.value)
               break
             case 'update':
               res = await updateXyoaUser(formData.value)
               break
             default:
               res = await createXyoaUser(formData.value)
               break
           }
           if (res.code === 0) {
             ElMessage({
               type: 'success',
               message: '创建/更改成功'
             })
           }
       })
}

// 返回按钮
const back = () => {
    router.go(-1)
}

</script>

<style>
</style>
